package com.leil.movies.project.controller;

import com.alibaba.fastjson.JSONObject;
import com.leil.movies.project.service.DouBanApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/douban_api")
public class DouBanApiController {

    DouBanApiService douBanApiService;

    @Autowired
    public void setDouBanApiService(DouBanApiService douBanApiService) {
        this.douBanApiService = douBanApiService;
    }

    @RequestMapping(value = "/cat_search", method = RequestMethod.GET)
    public JSONObject catSearch(@RequestParam("sort") String sort,
                                @RequestParam("tags") String tags,
                                @RequestParam("start") int start,
                                @RequestParam("genres") String genres) {
        JSONObject response = this.douBanApiService.catSearch(sort, tags, start, genres);
        return response;
    }

    @RequestMapping(value = "/subject_search", method = RequestMethod.GET)
    public JSONObject subjectSearch(@RequestParam("q") String q) {
        JSONObject response = this.douBanApiService.subjectSearch(q);
        return response;
    }

    @RequestMapping(value = "/subject/{id}", method = RequestMethod.GET)
    public JSONObject getSubject(@PathVariable("id") String id) {
        JSONObject response = this.douBanApiService.getSubject(id);
        return response;
    }

    @GetMapping(value = "/subject/{id}/photos")
    public JSONObject getSubjectPhotos(@PathVariable("id") String id, @RequestParam("start") int start, @RequestParam("count") int count) {
        JSONObject response = this.douBanApiService.getSubjectPhotos(id, start, count);
        return response;
    }

    @GetMapping(value = "/subject/{id}/reviews")
    public JSONObject getSubjectReviews(@PathVariable("id") String id, @RequestParam("start") int start, @RequestParam("count") int count) {
        JSONObject response = this.douBanApiService.getSubjectReviews(id, start, count);
        return response;
    }

    @GetMapping(value = "/subject/{id}/comments")
    public JSONObject getSubjectComments(@PathVariable("id") String id, @RequestParam("start") int start, @RequestParam("count") int count) {
        JSONObject response = this.douBanApiService.getSubjectComments(id, start, count);
        return response;
    }

    @GetMapping(value = "/celebrity/{id}")
    public JSONObject getCelebrity(@PathVariable("id") String id) {
        JSONObject response = this.douBanApiService.getCelebrity(id);
        return response;
    }

    @GetMapping(value = "/celebrity/{id}/works")
    public JSONObject getCelebrityWorks(@PathVariable("id") String id, @RequestParam("start") int start, @RequestParam("count") int count) {
        JSONObject response = this.douBanApiService.getCelebrityWorks(id, start, count);
        return response;
    }

    @GetMapping(value = "/celebrity/{id}/photos")
    public JSONObject getCelebrityPhotos(@PathVariable("id") String id, @RequestParam("start") int start, @RequestParam("count") int count) {
        JSONObject response = this.douBanApiService.getCelebrityPhotos(id, start, count);
        return response;
    }

    @GetMapping(value = "/top250")
    public JSONObject getTop250(@RequestParam("start") int start, @RequestParam("count") int count) {
        JSONObject response = this.douBanApiService.getTop250(start, count);
        return response;
    }


    @GetMapping(value = "/us_box")
    public JSONObject getUsBox() {
        JSONObject response = this.douBanApiService.getUsBox();
        return response;
    }

    @GetMapping(value = "/weekly")
    public JSONObject getWeekly() {
        JSONObject response = this.douBanApiService.getWeekly();
        return response;
    }

    @GetMapping(value = "/new_movies")
    public JSONObject getNewMovies() {
        JSONObject response = this.douBanApiService.getNewMovies();
        return response;
    }

    @GetMapping(value = "/in_theaters")
    public JSONObject getInTheaters() {
        JSONObject response = this.douBanApiService.getInTheaters();
        return response;
    }

    @GetMapping(value = "/coming_soon")
    public JSONObject getComingSoon(@RequestParam("start") int start, @RequestParam("count") int count) {
        JSONObject response = this.douBanApiService.getComingSoon(start, count);
        return response;
    }

}
